<cfcomponent extends="Controller" output="false">
	
	<cffunction name="index">
		<cfset seasons = model("Season").findAll()>
	</cffunction>
	
	<!--- -seasons/show/key --->
	<cffunction name="show">		
    	<cfset season = model("Season").findByKey(params.key)>  
	</cffunction>
		
	<!--- -seasons/new --->
	<cffunction name="new">
		<cfset season = model("Season").new()>
	</cffunction>
	
	
	<!--- -seasons/edit/key --->
	<cffunction name="edit">	
		<!--- Find the record --->
    	<cfset season = model("Season").findByKey(params.key)>
    	
    	<!--- Check if the record exists --->
	    <cfif NOT IsObject(season)>
	        <cfset flashInsert(error="Season #params.key# was not found")>
			<cfset redirectTo(action="index")>
	    </cfif>
		
	</cffunction>
	
	<!--- -seasons/create --->
	<cffunction name="create">
		<cfset season = model("Season").new(params.season)>
		<!--- Verify that the season creates successfully --->
		<cfif season.save()>
			<cfset flashInsert(success="The season was created successfully. #season.seasonid#")>
            <cfset redirectTo(action="index")>
		<!--- Otherwise --->
		<cfelse>
			<cfset flashInsert(error="There was an error creating the season.")>
			<cfset renderPage(action="new")>
		</cfif>
	</cffunction>
	
	<!--- -seasons/update --->
	<cffunction name="update">
		<cfset season = model("Season").findByKey(params.key)>
		
		<!--- Verify that the season updates successfully --->
		<cfif season.update(params.season)>
			<cfset flashInsert(success="The season was updated successfully.")>	
            <cfset redirectTo(action="index")>
		<!--- Otherwise --->
		<cfelse>
			<cfset flashInsert(error="There was an error updating the season.")>
			<cfset renderPage(action="edit")>
		</cfif>
	</cffunction>
	
	<!--- -seasons/delete/key --->
	<cffunction name="delete">
		<cfset season = model("Season").findByKey(params.key)>
		
		<!--- Verify that the season deletes successfully --->
		<cfif season.delete()>
			<cfset flashInsert(success="The season was deleted successfully.")>	
            <cfset redirectTo(action="index")>
		<!--- Otherwise --->
		<cfelse>
			<cfset flashInsert(error="Error occurred;" & errorMessagesFor("season"))>
			<cfset redirectTo(action="index")>
		</cfif>
	</cffunction>
	
</cfcomponent>
